package com.ssy.mall.controller;

import com.github.pagehelper.PageInfo;
import com.ssy.mall.common.ApiRestResponse;
import com.ssy.mall.service.OrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: 苏少有的idea
 * @date: 2022/1/6
 * @description 订单后台管理Controller
 */
@RestController
public class OrderAdminController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("管理员订单列表")
    @GetMapping("admin/order/list")
    public ApiRestResponse listForAdmin(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        PageInfo pageInfo = orderService.listForAdmin(pageNum, pageSize);
        return ApiRestResponse.success(pageInfo);
    }

    /**
     * 发货。订单状态流程： 0用户已取消 10未付款 20已付款 30已发货 40交易完成
     *
     * @param orderNo
     * @return
     */
    @ApiOperation("管理员发货")
    @PostMapping("admin/order/delivered")
    public ApiRestResponse delivered(@RequestParam String orderNo) {
        orderService.delivered(orderNo);
        return ApiRestResponse.success();
    }

    /**
     * 订单完结  管理员和用户都可以完结订单
     *
     * @param orderNo
     * @return
     */
    @ApiOperation("订单完结")
    @PostMapping("/order/finish")
    public ApiRestResponse finish(@RequestParam String orderNo) {
        orderService.finish(orderNo);
        return ApiRestResponse.success();
    }
}
